package com.rk.adapter;

import java.util.List;

import com.rk.entity.AppInfo;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

public class AppPagerAdapter extends PagerAdapter {

	private static final String TAG = "JK_AppPagerAdapter";
	private Context mContext;
	private List<View> mViews;

	public AppPagerAdapter(Context context, List<View> views) {
		this.mContext = context;
		this.mViews = views;
	}

	public void addView(View view) {
		mViews.add(view);
	}

	public void removeView(View view) {
		mViews.remove(view);
	}

	@Override
	public int getCount() {
		return mViews.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		((ViewPager) container).addView(mViews.get(position));
		return mViews.get(position);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView(mViews.get(position));
	}
}
